﻿@{
    ViewBag.Title = "ClassicalInheritance";
    Layout = "~/Views/Shared/_Page.cshtml";
}

<h2>Classical Inheritance</h2>

<script type="text/javascript">
    /* Class Person. */
    function Person(name) {
        this.name = name;
    }
    Person.prototype.getName = function () {
        return this.name;
    }

    /* Class Author. */
    function Author(name, books) {
        Person.call(this, name); // Call the superclass's constructor in the scope of this.
        this.books = books; // Add an attribute to Author.
    }
    Author.prototype = new Person(); // Set up the prototype chain.
    Author.prototype.constructor = Author; // Set the constructor attribute to Author.
    Author.prototype.getBooks = function () { // Add a method to Author.
        return this.books;
    };

    window.onload = function () {
        var author = [];
        author[0] = new Author('Dustin Diaz', ['JavaScript Design Patterns']);
        author[1] = new Author('Bruce Eckle', ['Thinking in Java', 'Thinking in C++']);
        ZEUS.DEBUG.log('author name: ' + author[1].getName());
        var books = author[1].getBooks();
        for (var i = 0; i < books.length; i++) {
            ZEUS.DEBUG.log(books[i]);
        }
    }
</script>
